home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / mallcrawl.swf / scripts / __Packages / BigKid.as next >
Encoding:
Text File  |  2007-09-28  |  4.5 KB  |  169 lines

  1. class BigKid extends MovieClip
  2. {
  3.    var glevel;
  4.    var is_available;
  5.    var direction;
  6.    var available_to_hit;
  7.    var move_speed;
  8.    var ground;
  9.    var hypnotized;
  10.    var BOUNDS;
  11.    var onEnterFrame;
  12.    var interval_id;
  13.    var last_escalator;
  14.    function BigKid()
  15.    {
  16.       super();
  17.       this._name = "BigKid";
  18.       _global[this._name] = this;
  19.       this.glevel = random(3) + 1;
  20.       this.is_available = true;
  21.       this.direction = -1;
  22.       this.available_to_hit = true;
  23.       this.move_speed = 5.5;
  24.       this.ground = _global.MallCrawl["GLevel" + this.glevel]._y - this._height;
  25.       this._y = this.ground;
  26.       this.hypnotized = false;
  27.       this.BOUNDS = {left:0,right:_global.MallCrawl.Background._width - this._width};
  28.       this.gotoAndStop("walk");
  29.       this.onEnterFrame = this.defaultEnterFrame;
  30.    }
  31.    function defaultEnterFrame()
  32.    {
  33.       if(!_global.MallCrawl.paused)
  34.       {
  35.          if(this.hitTest(_global.Rescuer) && this.is_available && this.available_to_hit && !_global.Rescuer.invincible)
  36.          {
  37.             _global.Rescuer.loseFollower();
  38.             this.available_to_hit = false;
  39.          }
  40.          else if(!this.hitTest(_global.Rescuer) && !this.available_to_hit)
  41.          {
  42.             this.available_to_hit = true;
  43.          }
  44.          if(this.is_available)
  45.          {
  46.             if(this.direction > 0)
  47.             {
  48.                this.moveRight();
  49.             }
  50.             else
  51.             {
  52.                this.moveLeft();
  53.             }
  54.             this.checkForEscalators();
  55.             this.checkBounds();
  56.          }
  57.          else
  58.          {
  59.             this._y = this.ground;
  60.          }
  61.       }
  62.    }
  63.    function checkForEscalators()
  64.    {
  65.       var _loc3_ = 0;
  66.       while(_loc3_ < _global.MallCrawl.upEscalators.length)
  67.       {
  68.          if(this.hitTest(_global.MallCrawl.upEscalators[_loc3_].HitSquare) && this.glevel < 3 && this.chance())
  69.          {
  70.             this.rideEscalator(_global.MallCrawl.upEscalators[_loc3_]);
  71.          }
  72.          _loc3_ = _loc3_ + 1;
  73.       }
  74.       _loc3_ = 0;
  75.       while(_loc3_ < _global.MallCrawl.downEscalators.length)
  76.       {
  77.          if(this.hitTest(_global.MallCrawl.downEscalators[_loc3_].HitSquare) && this.glevel > 1 && this.chance())
  78.          {
  79.             this.rideEscalator(_global.MallCrawl.downEscalators[_loc3_]);
  80.          }
  81.          _loc3_ = _loc3_ + 1;
  82.       }
  83.    }
  84.    function chance()
  85.    {
  86.       var _loc1_ = 30;
  87.       var _loc2_ = random(_loc1_);
  88.       if(_loc2_ === 0)
  89.       {
  90.          return true;
  91.       }
  92.       return false;
  93.    }
  94.    function escalate(escalator)
  95.    {
  96.       if(!this.hypnotized)
  97.       {
  98.          if(escalator.direction < 0)
  99.          {
  100.             if(this._y + this._height > escalator._y)
  101.             {
  102.                this.moveRight(1);
  103.                this.ground -= 1;
  104.             }
  105.             else
  106.             {
  107.                this.is_available = true;
  108.                this.resetGround();
  109.                clearInterval(this.interval_id);
  110.             }
  111.          }
  112.          else if(this._y + this._height < escalator._y + escalator._height)
  113.          {
  114.             this.moveRight(1);
  115.             this.ground += 1;
  116.          }
  117.          else
  118.          {
  119.             this.is_available = true;
  120.             this.resetGround();
  121.             clearInterval(this.interval_id);
  122.          }
  123.       }
  124.    }
  125.    function hypnotize()
  126.    {
  127.       this.gotoAndStop("head_bang");
  128.       this.hypnotized = true;
  129.       delete this.onEnterFrame;
  130.    }
  131.    function rideEscalator(escalator)
  132.    {
  133.       if(this._x < escalator._x && this._x + this._width > escalator._x && this.last_escalator != escalator)
  134.       {
  135.          this.is_available = false;
  136.          this.last_escalator = escalator;
  137.          escalator.activate(this);
  138.       }
  139.    }
  140.    function checkBounds()
  141.    {
  142.       if(this._x < this.BOUNDS.left)
  143.       {
  144.          this.direction *= -1;
  145.       }
  146.       else if(this._x > this.BOUNDS.right)
  147.       {
  148.          this.direction *= -1;
  149.       }
  150.    }
  151.    function resetGround()
  152.    {
  153.       this.ground = _global.MallCrawl["GLevel" + this.glevel]._y - this._height;
  154.       this._y = this.ground;
  155.    }
  156.    function moveLeft(speed)
  157.    {
  158.       !!speed ? null : (speed = this.move_speed);
  159.       this._xscale >= 0 ? null : (this._xscale *= -1);
  160.       this._x -= speed;
  161.    }
  162.    function moveRight(speed)
  163.    {
  164.       !!speed ? null : (speed = this.move_speed);
  165.       this._xscale <= 0 ? null : (this._xscale *= -1);
  166.       this._x += speed;
  167.    }
  168. }
  169.